<?php
namespace  app\util;
use Webman\Context;
use Webman\Http\Request;
use Workerman\Worker;

class SessionRequest extends  Request {


    public function __construct($buffer=null)
    {
        parent::__construct($buffer);
    }

//    //从头里获取
    public  function session(){
        if ($this->session === null) {
            $session_id = $this->sessionId();
            if ($session_id === false) {
                return false;
            }
            $this->session = new \Workerman\Protocols\Http\Session($session_id);
        }
        return $this->session;
    }


    public  function sessionId($session_id = null){

        if ($session_id) {
            unset($this->sid);
        }
        if (!isset($this->sid)) {
            $session_name = \Workerman\Protocols\Http\Session::$name;
            $sid = \request()->header($session_name);
            if(empty($sid)){
                return false;
            }

            $this->sid = $sid;
        }
        return $this->sid;
    }


}